/* Archive Extractor
 * Copyright 2008-2009 Matthew Hoops
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $URL: http://archive-extractor.googlecode.com/svn/trunk/stuffit.cpp $
 * $Id: stuffit.cpp 2 2009-03-23 01:29:43Z clone2727 $
 *
 */

#include "stuffit.h"

StuffItArchive::StuffItArchive() : StandardArchive() {
}

std::vector<const char*> StuffItArchive::getArchiveExtensions() {
	std::vector<const char*> exList;
	exList.push_back("sea");
	exList.push_back("sit");
	exList.push_back("sitx");
	return exList;
}

int StuffItArchive::detect(FILE* file) {
	uint32 tag = readUint32BE(file);
	
	// Old StuffIt/SEA Header
	if (tag == 'SIT!' || tag == 'ST46' || tag == 'ST50' || tag == 'ST60'
		|| tag == 'ST65' || tag == 'STin' || tag == 'STi2' || tag == 'STi3'
		|| tag == 'STi4') {
		_version = kStuffItOld;
		return 100;
	}
		
	// StuffIt5 Header
	fseek(file, 0, SEEK_SET);
	char strBuf[16 + 1];
	fread(strBuf, 1, 16, file);
	strBuf[16] = 0;
	if (!strcmp(strBuf, "StuffIt (c)1997-")) {
		_version = kStuffIt5;
		return 100;
	}
	
	// StuffItX Header
	if (!strncmp(strBuf, "StuffIt!", 8) || !strncmp(strBuf, "StuffIt?", 8)) {
		_version = kStuffItX;
		return 100;
	}
		
	return 0;
}

bool StuffItArchive::extractFiles(FILE* file) {
	// TODO! :P

	return false;
}
